# 首先需要安装mtcnn库: pip install mtcnn
from facenet_pytorch import MTCNN
import cv2

# 初始化 MTCNN 检测器
detector = MTCNN()

# 读取图像
image = cv2.imread('./data/face01.jpg')

# 检测人脸
faces = detector.detect_faces(image)

# 在检测到的人脸周围绘制矩形框和关键点
for face in faces:
    x, y, width, height = face['box']
    # 绘制人脸边界框
    cv2.rectangle(image, (x, y), (x+width, y+height), (255, 0, 0), 2)
    
    # 绘制人脸关键点
    for key, value in face['keypoints'].items():
        cv2.circle(image, value, 2, (0, 255, 0), 2)

# 显示结果
cv2.imshow('MTCNN Detection', image)
cv2.waitKey(0)
cv2.destroyAllWindows()


